﻿using System;
using System.Collections.Generic;
using ContractManager.Entity;
using Speed.Data;

namespace ContractManager.BLL.Business
{
    public static class ClsCategories
    {
        public static List<Categories> SelectAll()
        {
            using (var db = Sys.NewDb())
            {
                return Data.Base.Categories.Select(db);
            }
            
        }

        public static void Insert(Categories capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Insert<Categories>(capital);
            }
            
        }

        public static void Update(Categories capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Update<Categories>(capital);
            }
            
        }

        public static Categories SelectByPk(Int32 catId)
        {
            using (var db = Sys.NewDb())
            {
                return db.SelectSingle<Categories>(string.Format("CatId={0}", catId));
            }
            
        }

        public static Categories SelectByCode(string catCode)
        {
            using (var db = Sys.NewDb())
            {
                return db.SelectSingle<Categories>(string.Format("CatCode='{0}'", catCode));
            }
            
        }

        public static int DeleteByPk(Int32 catId)
        {
            using (var db = Sys.NewDb())
            {
                return db.Delete<Categories>(string.Format("CatId={0}", catId));
            }
            
        }
    }
}